﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Composite.Data;

public partial class Admin_LCASystem_Controls_AssignNewSystem : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadSystems();
        }
    }

    private void LoadSystems()
    {
        using (DataConnection conn = new DataConnection())
        {
            //// If a system can be attached with only ONE SystemCategory
            var systems = from s in conn.Get<LCA.Data.LCASystem>()
                          join scs in conn.Get<LCA.Data.LCASystemCategorySystem>() on s.Id equals scs.LCASystem into r1
                          from r2 in r1.DefaultIfEmpty()
                          where s.IsDeleted == false && r2.LCASystem == null
                          orderby s.Name
                          select new
                          {
                              ID = s.Id,
                              Name = s.Name
                          };

            ddlSystems.DataSource = systems;
            ddlSystems.DataBind();
        }
    }
}